﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Rea.Web.Models;
using Odyssey.Web.Models;

namespace Odyssey.Web.Controllers
{
    public class UserCenterController : FrontBaseController
    {
        //
        // GET: /UserCenter/
        [Login]
        public ActionResult Index()
        {
            if (!LoginHelper.CurrentUser.IsValidate)
            {
                return View("Validate");
            }

            ViewBag.Exhibitors = db.form_exhibitors.Where(c => c.State == 1).Take(6).ToList();
            ViewBag.Projects = db.form_projects.Where(c => c.State == 1 && c.AccountId != LoginHelper.CurrentUserId).Take(6).ToList();
            ViewBag.Referral = db.form_referral_applies.Where(c => c.State == 1).Take(6).ToList();
            ViewBag.MyProjects = db.form_projects.Where(c => c.State == 1 && c.AccountId == LoginHelper.CurrentUserId).Take(6).ToList();
            return View();
        }

        public ActionResult Validate(string act)
        {
            if (LoginHelper.CurrentUser.IsValidate)
            {
                return Redirect("/UserCenter");
            }

            if (act == "resend")
            {
                EmailSender.SendValidateEmail(LoginHelper.CurrentUser);
            }
            return View();
        }
    }
}
